﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LoadingMainScene : MonoBehaviour
{

	private AsyncOperation asyncOperation;//异步操作符

	private bool done;
	private void Awake()
	{
		StartCoroutine("LoadScene");
	}
	// Start is called before the first frame update
	void Start()
	{

	}
	private IEnumerator LoadScene()
	{
		yield return new WaitForSeconds(1f);
		asyncOperation = SceneManager.LoadSceneAsync(2);
		asyncOperation.allowSceneActivation = false;
		while (!asyncOperation.isDone)
		{
			yield return asyncOperation.isDone;
			if (asyncOperation.progress >= 0.89f && !asyncOperation.allowSceneActivation && !done)
			{
				Invoke("ContinueGame", 1f);
			}
		}
		UnityEngine.Debug.Log("load done");
	}
	public void ContinueGame()
	{
		done = true;
		StartCoroutine("WaitContinueGame");
	}
	private IEnumerator WaitContinueGame()
	{
		yield return new WaitForSeconds(1f);
		asyncOperation.allowSceneActivation = true;
	}
}
